package com.ruoyi.huanjing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.huanjing.domain.DirectoryManagement;
import com.ruoyi.huanjing.service.IDirectoryManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 目录管理Controller
 * 
 * @author ruoyi
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/xx/directoryManagement")
public class DirectoryManagementController extends BaseController
{
    @Autowired
    private IDirectoryManagementService directoryManagementService;

    /**
     * 查询目录管理列表
     */
    @PreAuthorize("@ss.hasPermi('xx:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(DirectoryManagement directoryManagement)
    {
        startPage();
        List<DirectoryManagement> list = directoryManagementService.selectDirectoryManagementList(directoryManagement);
        return getDataTable(list);
    }


    /**
     * 目录结构入库
     */
//    @PreAuthorize("@ss.hasPermi('xx:management:add')")
    @Log(title = "目录管理", businessType = BusinessType.INSERT)
    @Anonymous
    @PostMapping("/insertSql")
    public AjaxResult insertSql()
    {
        return toAjax(directoryManagementService.insertSql());
    }

    /**
     * 目录树结构
     */
//    @PreAuthorize("@ss.hasPermi('xx:management:add')")
    @Log(title = "目录树结构", businessType = BusinessType.INSERT)
    @Anonymous
    @PostMapping("/directoryTree")
    public AjaxResult directoryTree()
    {
        return success(directoryManagementService.directoryTree());
    }

    /**
     * 获取叹号展示信息
     * @param id
     * @return
     */
    @Anonymous
    @GetMapping("/getDirectoryInfo")
    public AjaxResult getDirectoryInfo(@RequestParam Long id) {
        return success(directoryManagementService.getDirectoryInfo(id));
    }

    /**
     * 导出目录管理列表
     */
    @PreAuthorize("@ss.hasPermi('xx:management:export')")
    @Log(title = "目录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DirectoryManagement directoryManagement)
    {
        List<DirectoryManagement> list = directoryManagementService.selectDirectoryManagementList(directoryManagement);
        ExcelUtil<DirectoryManagement> util = new ExcelUtil<DirectoryManagement>(DirectoryManagement.class);
        util.exportExcel(response, list, "目录管理数据");
    }

    /**
     * 获取目录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('xx:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(directoryManagementService.selectDirectoryManagementById(id));
    }

    /**
     * 新增目录管理
     */
    @PreAuthorize("@ss.hasPermi('xx:management:add')")
    @Log(title = "目录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DirectoryManagement directoryManagement)
    {
        return toAjax(directoryManagementService.insertDirectoryManagement(directoryManagement));
    }

    /**
     * 修改目录管理
     */
    @PreAuthorize("@ss.hasPermi('xx:management:edit')")
    @Log(title = "目录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DirectoryManagement directoryManagement)
    {
        return toAjax(directoryManagementService.updateDirectoryManagement(directoryManagement));
    }

    /**
     * 删除目录管理
     */
    @PreAuthorize("@ss.hasPermi('xx:management:remove')")
    @Log(title = "目录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(directoryManagementService.deleteDirectoryManagementByIds(ids));
    }
}
